package com.jz.controller;

import com.alibaba.fastjson.JSON;
import com.jz.Order;
import com.jz.Product;
import com.jz.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

//@RestController
//@RequestMapping("order")
//@Slf4j
public class OrderController2 {

//    @Autowired
//    private OrderService orderService;
//
//    @Autowired
//    private RestTemplate restTemplate;
//
//    @GetMapping("createOrder/{pid}")
//    public String createOrder(@PathVariable("pid")Integer pid){
//        log.info("下单开始~~~~~~~~~~~~~~~~~~~~~~~~~");
//        Order order=new Order();
//        order.setUid(1);
//        order.setUsername("张三");
//        order.setNumber(1);
//
//        //需要调用shop-product服务的接口? 服务之间如何调用。 restTemplate====>rest的模块 基于restful的形式来调用
//        log.info("调用远程查询商品接口~~~~~~~~~~~~~~~~");
//        Product product = restTemplate.getForObject("http://localhost:8081/product/findById/" + pid, Product.class);
//        log.info("返回商品信息："+ JSON.toJSONString(product));
//        order.setPprice(product.getPprice());
//        order.setPname(product.getPname());
//        order.setPid(product.getPid());
//
//        orderService.createOrder(order);
//        return "下单成功";
//    }
}
